/********************************************************************************************************************************
 * 《C ++ Primer》第五版中文版，读书笔记：按照书中的的示例源码和每一个小章节的课后习题，自己动手写代码实现，作为联系和测试。
 * Date: 2024-03-19 11:56
 * Author: dimon.chen 
 * EMali: 1181302388@qq.com 
 * 
 * 章节: 1.4.2 控制流 for 的使用
 *       1.4.2 节练习：
 *       1.12 编写程序，使用 for 循环将50到100的整数相加
 *       1.13 使用c--运算符
 *       1.14 提示用户输入两个数字，并输出两个数字之间的整数  
 * 
 ********************************************************************************************************************************/

#include <iostream>

int main(int argc, char *argvp[])
{
    int sum = 0;

    //从1加到10
    for(int val = 1; val <=10; val++){
        sum += val;
    }

    std::cout << "Sum of 1 to 10 inclusive is "
              << sum << std::endl;
    

    //Examine 1.12
    sum = 0;
    for(int i=-100; i<=100; i++){
        sum += i;
    }
    std::cout << "Sum of -100 to 100 inclusive is "
              << sum << std::endl;

    //Examine 1.13 
    sum = 0;
    for(int i=50; i<=100; i++){
        sum += i;
    }
    std::cout << "Sum of 50 to 100 inclusive is "
              << sum << std::endl;

    //Exmaine 1.14
    std::cout << "The number between 10 and 0 decrease is "
              << std::endl;
    for(int i=10; i>=0; i--){
        std::cout << i << " ";
    }
    std::cout << std::endl;


    //Exmaine 1.15
    std::cout << "Enter two number, it will print the number between the two number of you Enter:"
              << std::endl;
    int v1 = 0;
    int v2 = 0;
    std::cin >> v1 >> v2;
    if(v1 < v2){
        if(v1+1 < v2){
            for(int i=v1+1; i<v2 ; i++){
                std::cout << i << std::endl;
            }
        }
        else{
            std::cout << "there is no number between the number you Enter: " << v1 << " and " << v2 << std::endl; 
        }
    }
    else if(v1 > v2)
    {
        if(v2+1 < v1){
            for(int i=v2+1; i<v1 ; i++){
                std::cout << i << std::endl;
            }
        }
        else{
            std::cout << "there is no number between the number you Enter: " << v1 << " and " << v2 << std::endl; 
        }
    }
    else if(v1 == v2){
        std::cout << "the number you Enter: " << v1 << " and " << v2 << " is equal " << std::endl;
    }

    return 0;
}